package day4.homework;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

//a.设计一个类简单的类 有参构造方法私有化了  通过反射使用有参构造把该对象创建出来?
public
class Demo1 {
    public static
    void main(String[] args) {
        try {
            Class c=Class.forName("day4.homework.Cat");
            Constructor co= c.getDeclaredConstructor(String.class,Integer.class,String.class);
            co.setAccessible(true);
            Cat cat=(Cat)co.newInstance("咪咪",5,"橘猫");
            System.out.println(cat.name+" "+cat.age+" "+cat.type);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
class Cat{
    String name="耄耋";
    Integer age=0;
    String type="橘猫";
    private Cat(String name, Integer age, String type){
        this.name=name;
        this.age=age;
        this.type=type;
    }
    public Cat(){

    }
}
